﻿/*
*VMukti -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, VMukti Solutions Pvt. Ltd.
*
* Hardik Sanghvi <hardik@vmukti.com>
*
* See http://www.vmukti.com for more information about
* the VMukti project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using VMukti.Business;
using VMukti.Business.CommonDataContracts;
using VMukti.CtlResizer.Presentation;
using VMukti.Presentation.Controls;
using VMuktiAPI;

namespace VMukti.Presentation.MainPod
{
	/// <summary>
	/// Interaction logic for CtlPod.xaml
	/// </summary>
	public partial class CtlPod : UserControl, IDisposable
	{
		#region Variables

		public double TitleX = 0;
		public double TitleY = 0;
		public double dblOldHeight = 0;
		public double dblOldWidth = 0;
		public double dblOldLeft = 0;
		public double dblOldTop = 0;
		public bool mDown = false;

		public bool blnMaxPOD = false;
		string strCtlname = "";

		bool blnMaxPODID = false;

		public bool blnMaxFlag = false;

		int intPodId = 0;
		int intModId = 0;
		string intTabId = "0";
		string strPageId = "";
		string strModUri = "";
		int[] intModPerm;

		private bool blndisposed = false;

		public ArrayList al = new ArrayList();

		public delegate void PodDelegate(object objnew);
		public PodDelegate pDel = null;

		public delegate void DynModuleDelegate(object objnew);
		public DynModuleDelegate dModDel = null;

		public delegate void DynPageDelegate(object objnew);
		public DynPageDelegate dPageDel = null;

		Assembly ass = null;

		Assembly a;

		string MyRole = "";

		string[] strUri;

		//public bool blnResizeFlag = false;

		public static bool blnPodResize = false;

		public delegate void DelMainPodMouseDown(double height, double width, double x, double y, string mState);
		public event DelMainPodMouseDown EntMainPodMouseDown;

		public delegate void DelCnvPodBodyDrop(string from, string to, string msg, clsModuleInfo cmi);
		public event DelCnvPodBodyDrop EntCnvPodBodyDrop;

		public delegate bool DelSavePage();
		public event DelSavePage EntSavePage;

		public delegate void DelRemoveBuddy(string from, List<string> to, string msg, clsModuleInfo cmi);
		public event DelRemoveBuddy EntRemoveBuddy;


		public bool blnBuddyType = true;

		static double dblDBLeft = 0.0;
		static double dblDBTop = 0.0;
		static double dblDBHeight = 0.0;
		static double dblDBWidth = 0.0;

		public List<string> lstUsersDropped = new List<string>();

		#endregion

		#region Constructors

		public CtlPod()
		{
			InitializeComponent();
		}

		//public CtlPod(string[] strWCFUri, int intModuleId, string strModuleTitle)
		//{
		//    InitializeComponent();

		//    ass = Assembly.GetAssembly(typeof(CtlPod));

		//    object[] objarray = new object[2];
		//    dblOldHeight = this.Height;
		//    dblOldWidth = this.Width;

		//    this.Tag = "";

		//    pDel = new PodDelegate(ControlThread);

		//    //if (Environment.MachineName.ToLower() == "adiance02")
		//    //{
		//    //    MyRole = "Host";
		//    //    btnMaximized.Visibility = Visibility.Visible;
		//    //    btnMinimized.Visibility = Visibility.Visible;
		//    //}
		//    //else
		//    //{
		//    //    MyRole = "Guest";
		//    //    btnMaximized.Visibility = Visibility.Collapsed;
		//    //    btnMinimized.Visibility = Visibility.Collapsed;
		//    //}

		//    btnMaximized.Visibility = Visibility.Visible;
		//    btnMinimized.Visibility = Visibility.Visible;

		//    Thread th = new Thread(new ParameterizedThreadStart(ControlDispatcher));
		//    objarray[0] = intModuleId;
		//    objarray[1] = strModuleTitle;
		//    objarray[2] = strWCFUri;

		//    this.WCFUri = strWCFUri;

		//    th.Start(objarray);

		//    #region Events

		//    this.Loaded += new RoutedEventHandler(ClsPod_Loaded);
		//    this.Unloaded += new RoutedEventHandler(ClsPod_Unloaded);
		//    this.PreviewMouseDown += new MouseButtonEventHandler(ClsPod_PreviewMouseDown);
		//    this.cnvTitle.MouseDown += new MouseButtonEventHandler(cnvTitle_MouseDown);
		//    this.cnvTitle.MouseUp += new MouseButtonEventHandler(cnvTitle_MouseUp);
		//    this.btnMaximized.Click += new RoutedEventHandler(btnMaximized_Click);
		//    this.btnMinimized.Click += new RoutedEventHandler(btnMinimized_Click);
		//    this.cnvPodBody.SizeChanged += new SizeChangedEventHandler(cnvPodBody_SizeChanged);
		//    this.PreviewDrop += new DragEventHandler(CtlPod_PreviewDrop);
		//    //cnvPodBody.Drop += new DragEventHandler(cnvPodBody_Drop);
		//    //cnvPodBody.PreviewDrop += new DragEventHandler(cnvPodBody_PreviewDrop);

		//    #endregion

		//    cnvMainPOD.PreviewMouseMove += new MouseEventHandler(cnvMainPOD_PreviewMouseMove);
		//}

		//public CtlPod(int intModuleId, string strModuleTitle, string strIsCollaborative, string Uri, int[] arrPermissionValue)
		//{
		//    InitializeComponent();

		//    try
		//    {
		//        ass = Assembly.GetAssembly(typeof(CtlPod));

		//        dblOldHeight = this.Height;
		//        dblOldWidth = this.Width;

		//        this.Tag = "";

		//        pDel = new PodDelegate(ControlThread);

		//        btnMaximized.Visibility = Visibility.Visible;
		//        btnMinimized.Visibility = Visibility.Visible;


		//        #region Events

		//        this.Loaded += new RoutedEventHandler(ClsPod_Loaded);
		//        this.Unloaded += new RoutedEventHandler(ClsPod_Unloaded);
		//        this.PreviewMouseDown += new MouseButtonEventHandler(ClsPod_PreviewMouseDown);
		//        this.cnvTitle.MouseDown += new MouseButtonEventHandler(cnvTitle_MouseDown);
		//        this.cnvTitle.MouseUp += new MouseButtonEventHandler(cnvTitle_MouseUp);
		//        this.btnMaximized.Click += new RoutedEventHandler(btnMaximized_Click);
		//        this.btnMinimized.Click += new RoutedEventHandler(btnMinimized_Click);
		//        this.cnvPodBody.SizeChanged += new SizeChangedEventHandler(cnvPodBody_SizeChanged);
		//        cnvMainPOD.PreviewMouseMove += new MouseEventHandler(cnvMainPOD_PreviewMouseMove);
		//        this.PreviewDrop += new DragEventHandler(CtlPod_PreviewDrop);
		//        //cnvPodBody.PreviewDrop += new DragEventHandler(cnvPodBody_PreviewDrop);
		//        #endregion

		//        if (bool.Parse(strIsCollaborative) && Uri == null)
		//        {
		//            Thread th = new Thread(new ParameterizedThreadStart(ControlDispatcher));
		//            object[] objarray = new object[4];
		//            objarray[0] = intModuleId;
		//            objarray[1] = strModuleTitle;
		//            //string[] tempUris = ClsGlobal.clientHttpChannelSN.svcStartAService(VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType, intModuleId.ToString());
		//            string[] tempUris = App.chHttpSuperNodeService.svcStartAService(VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType, intModuleId.ToString());

		//            this.WCFUri = tempUris;
		//            //if (VMuktiGlobal.objBindingType == BindingType.NetP2P)
		//            if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.BootStrap || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.SuperNode || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithNetP2P)
		//            {
		//                objarray[2] = tempUris[0];
		//            }
		//            //else if (VMuktiGlobal.objBindingType == BindingType.Http)
		//            else if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithHttp)
		//            {
		//                objarray[2] = tempUris[1];
		//            }

		//            objarray[3] = arrPermissionValue;
		//            th.Start(objarray);
		//        }
		//        else if (bool.Parse(strIsCollaborative) && Uri != null)
		//        {
		//            Thread th = new Thread(new ParameterizedThreadStart(ControlDispatcher));
		//            object[] objarray = new object[4];
		//            objarray[0] = intModuleId;
		//            objarray[1] = strModuleTitle;
		//            objarray[2] = Uri;
		//            objarray[3] = arrPermissionValue;
		//            //if (VMuktiGlobal.objBindingType == BindingType.NetP2P)
		//            if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.BootStrap || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.SuperNode || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithNetP2P)
		//            {
		//                this.WCFUri = new string[2];
		//                this.WCFUri[0] = Uri;
		//            }
		//            //else if (VMuktiGlobal.objBindingType == BindingType.Http)
		//            else if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithHttp)
		//            {
		//                this.WCFUri = new string[2];
		//                this.WCFUri[1] = Uri;
		//            }
		//            th.Start(objarray);
		//        }
		//        else
		//        {
		//            Thread th = new Thread(new ParameterizedThreadStart(ControlDispatcher));
		//            object[] objarray = new object[3];
		//            objarray[0] = intModuleId;
		//            objarray[1] = strModuleTitle;
		//            objarray[2] = arrPermissionValue;
		//            this.WCFUri = null;
		//            th.Start(objarray);
		//        }
		//    }
		//    catch (Exception exp)
		//    {
		//        MessageBox.Show("CtlPod3 " + exp.Message);
		//    }
		//}

		public CtlPod(int intModuleId, string strModuleTitle, string strIsCollaborative, string Uri, int[] arrPermissionValue, string displayname)
		{
			InitializeComponent();

			try
			{
				ass = Assembly.GetAssembly(typeof(CtlPod));

				dblOldHeight = this.Height;
				dblOldWidth = this.Width;

				this.Tag = "";


				dModDel = new DynModuleDelegate(ModuleThread);


				btnMaximized.Visibility = Visibility.Visible;
				btnMinimized.Visibility = Visibility.Visible;


				#region Events

				this.Loaded += new RoutedEventHandler(ClsPod_Loaded);
				this.Unloaded += new RoutedEventHandler(ClsPod_Unloaded);
				this.PreviewMouseDown += new MouseButtonEventHandler(ClsPod_PreviewMouseDown);
				this.cnvTitle.MouseDown += new MouseButtonEventHandler(cnvTitle_MouseDown);
				this.cnvTitle.MouseUp += new MouseButtonEventHandler(cnvTitle_MouseUp);
				this.btnMaximized.Click += new RoutedEventHandler(btnMaximized_Click);
				this.btnMinimized.Click += new RoutedEventHandler(btnMinimized_Click);
				this.cnvPodBody.SizeChanged += new SizeChangedEventHandler(cnvPodBody_SizeChanged);
				cnvMainPOD.PreviewMouseMove += new MouseEventHandler(cnvMainPOD_PreviewMouseMove);
				this.PreviewDrop += new DragEventHandler(CtlPod_PreviewDrop);
				#endregion

				if (bool.Parse(strIsCollaborative) && Uri != null)
				{
					Thread th = new Thread(new ParameterizedThreadStart(DynModuleDispatcher));
					object[] objarray = new object[5];
					objarray[0] = intModuleId;
					objarray[1] = strModuleTitle;
					objarray[2] = Uri;
					objarray[3] = arrPermissionValue;
					objarray[4] = displayname;
					if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.BootStrap || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.SuperNode || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithNetP2P)
					{
						this.WCFUri = new string[2];
						this.WCFUri[0] = Uri;
					}
					else if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithHttp)
					{
						this.WCFUri = new string[2];
						this.WCFUri[1] = Uri;
					}
					th.Start(objarray);
				}
			}
			catch (Exception exp)
			{
				//MessageBox.Show("CtlPod3 " + exp.Message);
				exp.Data.Add("My Key", "CtlPod4--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);

			}
		}

		public CtlPod(int intModuleId, string strModuleTitle, string strIsCollaborative, string Uri, int[] arrPermissionValue, bool flag)
		{
			InitializeComponent();

			try
			{
				ass = Assembly.GetAssembly(typeof(CtlPod));

				dblOldHeight = this.Height;
				dblOldWidth = this.Width;

				this.Tag = "";

				dPageDel = new DynPageDelegate(PageThread);



				btnMaximized.Visibility = Visibility.Visible;
				btnMinimized.Visibility = Visibility.Visible;


				#region Events

				this.Loaded += new RoutedEventHandler(ClsPod_Loaded);
				this.Unloaded += new RoutedEventHandler(ClsPod_Unloaded);
				this.PreviewMouseDown += new MouseButtonEventHandler(ClsPod_PreviewMouseDown);
				this.cnvTitle.MouseDown += new MouseButtonEventHandler(cnvTitle_MouseDown);
				this.cnvTitle.MouseUp += new MouseButtonEventHandler(cnvTitle_MouseUp);
				this.btnMaximized.Click += new RoutedEventHandler(btnMaximized_Click);
				this.btnMinimized.Click += new RoutedEventHandler(btnMinimized_Click);
				this.cnvPodBody.SizeChanged += new SizeChangedEventHandler(cnvPodBody_SizeChanged);
				cnvMainPOD.PreviewMouseMove += new MouseEventHandler(cnvMainPOD_PreviewMouseMove);
				this.PreviewDrop += new DragEventHandler(CtlPod_PreviewDrop);
				//cnvPodBody.PreviewDrop += new DragEventHandler(cnvPodBody_PreviewDrop);
				#endregion

				if (bool.Parse(strIsCollaborative) && Uri == null)
				{
					Thread th = new Thread(new ParameterizedThreadStart(PageDispatcher));
					object[] objarray = new object[5];
					objarray[0] = intModuleId;
					objarray[1] = strModuleTitle;
                    string[] tempUris = null;
					//string[] tempUris = ClsGlobal.clientHttpChannelSN.svcStartAService(VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType, intModuleId.ToString());
                    try
                    {
                        tempUris = App.chHttpSuperNodeService.svcStartAService(VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType, intModuleId.ToString());
                    }
                    catch (System.ServiceModel.EndpointNotFoundException e)
                    {
                        e.Data.Add("My Key", "CtlPod()--:--CtlPod.xaml.cs--:--" + e.Message + " :--:--");
                        ClsException.LogError(e);
                        ClsException.WriteToErrorLogFile(e);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        tempUris = App.chHttpSuperNodeService.svcStartAService(VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType, intModuleId.ToString());
                    }
                    catch (System.ServiceModel.CommunicationException ex)
                    {
                        ex.Data.Add("My Key", "CtlPod()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
                        ClsException.LogError(ex);
                        ClsException.WriteToErrorLogFile(ex);
                        VMuktiAPI.VMuktiHelper.CallEvent("GetSuperNodeIP", null, null);
                        tempUris = App.chHttpSuperNodeService.svcStartAService(VMuktiAPI.VMuktiInfo.CurrentPeer.CurrPeerType, intModuleId.ToString());
                    }

					this.WCFUri = tempUris;
					//if (VMuktiGlobal.objBindingType == BindingType.NetP2P)
					if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.BootStrap || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.SuperNode || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithNetP2P)
					{
						objarray[2] = tempUris[0];
					}
					//else if (VMuktiGlobal.objBindingType == BindingType.Http)
					else if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithHttp)
					{
						objarray[2] = tempUris[1];
					}

					objarray[3] = arrPermissionValue;
					objarray[4] = flag;
					th.Start(objarray);
				}
				else if (bool.Parse(strIsCollaborative) && Uri != null)
				{
					Thread th = new Thread(new ParameterizedThreadStart(PageDispatcher));
					object[] objarray = new object[5];
					objarray[0] = intModuleId;
					objarray[1] = strModuleTitle;
					objarray[2] = Uri;
					objarray[3] = arrPermissionValue;
					objarray[4] = flag;
					//if (VMuktiGlobal.objBindingType == BindingType.NetP2P)
					if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.BootStrap || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.SuperNode || VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithNetP2P)
					{
						this.WCFUri = new string[2];
						this.WCFUri[0] = Uri;
					}
					//else if (VMuktiGlobal.objBindingType == BindingType.Http)
					else if (VMuktiInfo.CurrentPeer.CurrPeerType == PeerType.NodeWithHttp)
					{
						this.WCFUri = new string[2];
						this.WCFUri[1] = Uri;
					}
					th.Start(objarray);
				}
				else
				{
					Thread th = new Thread(new ParameterizedThreadStart(PageDispatcher));
					object[] objarray = new object[4];
					objarray[0] = intModuleId;
					objarray[1] = strModuleTitle;
					objarray[2] = arrPermissionValue;
					objarray[3] = flag;
					this.WCFUri = null;
					th.Start(objarray);
				}
			}
			catch (Exception exp)
			{
				//MessageBox.Show("CtlPod3 " + exp.Message);
				exp.Data.Add("My Key", "CtlPod5--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		#endregion

		#region Properties

		public string Text
		{
			get { return lblTitle.Content.ToString(); }
			set { lblTitle.Content = value; }
		}

		public string ControlName
		{
			get { return strCtlname; }
			set { strCtlname = value; }
		}

		public int PID
		{
			get { return intPodId; }
			set { intPodId = value; }
		}

		public int ModID
		{
			get { return intModId; }
			set { intModId = value; }
		}

		public bool MaxId
		{
			get { return blnMaxPODID; }
			set { blnMaxPODID = value; }
		}

		public string TabId
		{
			get
			{
				return intTabId;
			}
			set
			{
				intTabId = value;
			}
		}

		public string PageId
		{
			get
			{
				return strPageId;
			}
			set
			{
				strPageId = value;
			}
		}

		public string ModUri
		{
			get
			{
				return strModUri;
			}
			set
			{
				strModUri = value;
			}
		}

		public int[] ModPer
		{
			get
			{
				return intModPerm;
			}
			set
			{
				intModPerm = value;
			}
		}

		public string[] WCFUri
		{
			get
			{
				return strUri;
			}
			set
			{
				strUri = value;
			}
		}

		public bool ResizePod
		{
			get
			{
				return blnPodResize;
			}
			set
			{
				blnPodResize = value;
			}
		}

		public double DBLeft
		{
			get
			{
				return dblDBLeft;
			}
			set
			{
				dblDBLeft = value;
			}
		}

		public double DBTop
		{
			get
			{
				return dblDBTop;
			}
			set
			{
				dblDBTop = value;
			}
		}

		public double DBHeight
		{
			get
			{
				return dblDBHeight;
			}
			set
			{
				dblDBHeight = value;
			}
		}

		public double DBWidth
		{
			get
			{
				return dblDBWidth;
			}
			set
			{
				dblDBWidth = value;
			}
		}

		#endregion

		#region EventHandlers

		void cnvPodBody_SizeChanged(object sender, SizeChangedEventArgs e)
		{
			try
			{
				for (int i = 0; i < cnvPodBody.Children.Count; i++)
				{
					if (cnvPodBody.Tag != null)
					{
						if (cnvPodBody.Children[i].GetType().ToString() == cnvPodBody.Tag.ToString())
						{
							if (e.NewSize.Height >= 3.0)
							{
								((UserControl)cnvPodBody.Children[i]).Height = e.NewSize.Height - 3.0;
								((UserControl)cnvPodBody.Children[i]).Width = e.NewSize.Width - 3.0;
							}
							else
							{
								((UserControl)cnvPodBody.Children[i]).Height = e.NewSize.Height;
								((UserControl)cnvPodBody.Children[i]).Width = e.NewSize.Width;
							}
						}
					}
				}
			}
			catch (Exception exp)
			{
				//MessageBox.Show("cnvBody_SizeChanged " + exp.Message);
				exp.Data.Add("My Key", "cnvBody_SizeChanged--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		public void btnMinimized_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (cnvPodBody.Children.Count >= 2)
				{
					MethodInfo mi = cnvPodBody.Children[1].GetType().GetMethod("ClosePod");
					if (mi != null)
					{
						mi.Invoke(cnvPodBody.Children[1], null);
					}
					if (this.cmbPodBuddy.Items.Count > 0 || this.lstUsersDropped.Count > 0)
					{
						clsModuleInfo cmi = new clsModuleInfo();
						cmi.strPageid = this.PageId;
						cmi.strTabid = this.TabId;
						cmi.strPodid = this.PID.ToString();
						cmi.strDropType = "Pod Type";
						if (EntRemoveBuddy != null)
						{
							EntRemoveBuddy(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, this.lstUsersDropped, "CLOSE MODULE", cmi);
						}
						//EntCnvPodBodyDrop(VMuktiAPI.VMuktiInfo.CurrentPeer.DisplayName, "", "CLOSE MODULE", cmi);

					}
					((Canvas)((Resizer)this.Parent).Parent).Children.Remove(((Resizer)this.Parent));
				}
			}
			catch (Exception exp)
			{
				//MessageBox.Show("btnMaximized_Click" + exp.Message);
				exp.Data.Add("My Key", "btnMinimized_Click--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}

		}

		void btnMaximized_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				//if (MyRole == "Host")
				//{
				if (blnMaxPOD)
				{
					this.SetValue(InkCanvas.LeftProperty, dblOldLeft);
					this.SetValue(InkCanvas.TopProperty, dblOldTop);
					this.Height = dblOldHeight;
					this.Width = dblOldWidth;
					((Resizer)this.Parent).Height = dblOldHeight;
					((Resizer)this.Parent).Width = dblOldWidth;

					btnMaximized.ToolTip = "Maximize";
					blnMaxPOD = false;
				}
				else
				{
					dblOldHeight = cnvMainPOD.Height;
					dblOldWidth = cnvMainPOD.Width;
					dblOldLeft = (double)this.GetValue(Canvas.LeftProperty);
					dblOldTop = (double)this.GetValue(Canvas.TopProperty);

					this.Height = 450;
					this.Width = 600;
					this.SetValue(Canvas.LeftProperty, 5.0);
					this.SetValue(Canvas.TopProperty, 5.0);
					((Resizer)this.Parent).Height = 450;
					((Resizer)this.Parent).Width = 600;

					btnMaximized.ToolTip = "Restore";
					blnMaxPOD = true;
				}
				//if (this.PID != 0)
				//{
				//    CtlDesignerControl.channelPod.WSvcMaxPod((double)this.GetValue(Canvas.LeftProperty), (double)this.GetValue(Canvas.TopProperty), this.Width, this.Height, this.PID, this.blnMaxPOD, this.TabId, "1");
				//}
				//}
			}
			catch (Exception exp)
			{
				//MessageBox.Show("btnMaximized_Click" + exp.Message);
				exp.Data.Add("My Key", "btnMaximized_Click--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		public void ClsPod_PreviewMouseDown(object sender, MouseButtonEventArgs e)
		{
			try
			{
				this.Tag = ((Resizer)this.Parent).Parent;
				((Canvas)this.Tag).Children.Remove((UIElement)(((CtlPod)sender).Parent));
				((Canvas)this.Tag).Children.Add((UIElement)(((CtlPod)sender).Parent));
			}
			catch (Exception exp)
			{
				//MessageBox.Show("ClsPod_PreviewMouseDown" + exp.Message);
				exp.Data.Add("My Key", "ClsPod_PreviewMouseDown--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		void ClsPod_Unloaded(object sender, RoutedEventArgs e)
		{
		}

		void ClsPod_Loaded(object sender, RoutedEventArgs e)
		{
			try
			{
				dblOldLeft = (double)this.GetValue(Canvas.LeftProperty);
				dblOldTop = (double)this.GetValue(Canvas.TopProperty);
				dblOldHeight = this.Height;
				dblOldWidth = this.Width;
			}
			catch (Exception exp)
			{
				//MessageBox.Show("ClsPod_Loaded" + exp.Message);
				exp.Data.Add("My Key", "ClsPod_Loaded-1--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}

		}

		void cnvTitle_MouseUp(object sender, MouseButtonEventArgs e)
		{
			try
			{
				((Canvas)((Resizer)this.Parent).Parent).Tag = "Mouse Up";
				mDown = false;
				this.Cursor = Cursors.Arrow;
			}
			catch (Exception exp)
			{
				//MessageBox.Show("cnvTitle_PreviewMouseUp" + exp.Message);
				exp.Data.Add("My Key", "cnvTitle_PreviewMouseUp--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		void cnvTitle_MouseDown(object sender, MouseButtonEventArgs e)
		{
			try
			{
				TitleX = e.GetPosition(this).X;
				TitleY = e.GetPosition(this).Y;

				this.SetValue(Canvas.LeftProperty, ((Resizer)this.Parent).GetValue(Canvas.LeftProperty));
				this.SetValue(Canvas.TopProperty, ((Resizer)this.Parent).GetValue(Canvas.TopProperty));

				//MessageBox.Show("this.left " + this.GetValue(Canvas.LeftProperty));
				//MessageBox.Show("this.top " + this.GetValue(Canvas.TopProperty));

				//MessageBox.Show("resizerX.left " + e.GetPosition((Resizer)this.Parent).X.ToString());
				//MessageBox.Show("resizerY.top " + e.GetPosition((Resizer)this.Parent).Y.ToString());

				//MessageBox.Show("resizer.left " + ((Resizer)this.Parent).GetValue(Canvas.LeftProperty));
				//MessageBox.Show("resizer.top " + ((Resizer)this.Parent).GetValue(Canvas.TopProperty));

				this.ResizePod = true;
				((Canvas)((Resizer)this.Parent).Parent).Tag = this;
				mDown = true;
				this.Cursor = Cursors.SizeAll;
			}
			catch (Exception exp)
			{
				//MessageBox.Show(exp.Message);
				exp.Data.Add("My Key", "cnvTitle_MouseDown--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		void cnvMainPOD_PreviewMouseMove(object sender, MouseEventArgs e)
		{
			//if (EntMainPodMouseDown != null )
			//{
			//    EntMainPodMouseDown(this.Height, this.Width, e.GetPosition(((Canvas)((Resizer)(this.Parent)).Parent)).X, e.GetPosition(((Canvas)((Resizer)(this.Parent)).Parent)).Y,e.LeftButton.ToString());
			//}

			if (Math.Round(((Canvas)((Resizer)this.Parent).Parent).Width) < Math.Round((this.Width + e.GetPosition(((Canvas)((Resizer)(this.Parent)).Parent)).X)))
			{
				((Canvas)((Resizer)this.Parent).Parent).Width = this.Width + e.GetPosition(((Canvas)((Resizer)(this.Parent)).Parent)).X;
			}
			if (Math.Round(((Canvas)((Resizer)this.Parent).Parent).Height) < Math.Round((this.Height + e.GetPosition(((Canvas)((Resizer)(this.Parent)).Parent)).Y)))
			{
				((Canvas)((Resizer)this.Parent).Parent).Height = Math.Round(this.Height + e.GetPosition(((Canvas)((Resizer)(this.Parent)).Parent)).Y);
			}
			//MessageBox.Show("Y" +e.GetPosition(((Canvas)((Resizer)(this.Parent)).Parent)).Y.ToString());
			//MessageBox.Show("X" +e.GetPosition(((Canvas)((Resizer)(this.Parent)).Parent)).X.ToString());
		}

		void cnvPodBody_PreviewDrop(object sender, DragEventArgs e)
		{
			try
			{

				#region BuddylistDrag/Drop

				if (e.Data.GetDataPresent(typeof(ListBoxItem)))
				{

					//MessageBoxResult r;
					//r = MessageBox.Show("Do you want to save this page?", "Save Page", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes);
					//if (r == MessageBoxResult.Yes)
					//{
					//    //save the page
					//    //cpt.SavePage();
					//    EntSavePage();
					//}
					bool tmpBool = EntSavePage();

					if (tmpBool)
					{
						if (((ListBoxItem)e.Data.GetData(typeof(ListBoxItem))).Tag != null)
						{
							// Pratik is not getting.
							//VMuktiGlobal.CallEventMethod(((ListBoxItem)e.Data.GetData(typeof(ListBoxItem))).Content.ToString().Trim());
							// Pratik is not getting.
							try
							{

								clsModuleInfo cmi = new clsModuleInfo();
								cmi.intModuleId = this.ModID;
								cmi.strModuleName = this.Text;
								cmi.strUri = this.WCFUri;
								cmi.strPageid = this.PageId;
								cmi.strTabid = this.TabId;
								cmi.ModPermissions = this.ModPer;

								EntCnvPodBodyDrop(VMuktiInfo.CurrentPeer.DisplayName, ((ListBoxItem)e.Data.GetData(typeof(ListBoxItem))).Content.ToString(), "OPEN_MODULE", cmi);
							}
							catch (Exception exp)
							{
								//MessageBox.Show("cnvNew_Drop2" + exp.Message);
								exp.Data.Add("My Key", "cnvNew_Drop6--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
								ClsException.LogError(exp);
								ClsException.WriteToErrorLogFile(exp);
							}
						}
					}
					else
					{
						MessageBox.Show("Save the page to Collaborate");
					}
				}
				#endregion
			}
			catch (Exception exp)
			{
				//MessageBox.Show("Canvas_Drop " + exp.Message);
				exp.Data.Add("My Key", "Canvas_Drop--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		void CtlPod_PreviewDrop(object sender, DragEventArgs e)
		{
			bool flag = false;
			try
			{
				#region BuddylistDrag/Drop

				if (e.Data.GetDataPresent(typeof(CtlExpanderItem)))
				{
					string[] strTag = ((VMukti.Presentation.Controls.CtlExpanderItem)e.Data.GetData(typeof(VMukti.Presentation.Controls.CtlExpanderItem))).Tag.ToString().Split(',');
					List<string> lstTag = new List<string>();
					for (int i = 0; i < strTag.Length; i++)
					{
						//lstTag.Add(strTag[i]);
						if (strTag[i] == "ModuleType")
						{
							blnBuddyType = false;
							break;
						}
					}

					if (blnBuddyType)
					{
						bool tmpBool = EntSavePage();

						if (tmpBool)
						{
							if (((VMukti.Presentation.Controls.CtlExpanderItem)e.Data.GetData(typeof(VMukti.Presentation.Controls.CtlExpanderItem))).Tag != null)
							{
								lstTag.Add(((VMukti.Presentation.Controls.CtlExpanderItem)e.Data.GetData(typeof(VMukti.Presentation.Controls.CtlExpanderItem))).Caption);

								//object[] obj = new object[] { ((CtlExpanderItem)e.Data.GetData(typeof(CtlExpanderItem))).Caption };
								object[] obj = new object[] { lstTag };

								//MethodInfo mi = cnvPodBody.Children[1].GetType().GetMethod("BuddySelected");
								//if (mi != null)
								//{
								//    mi.Invoke(cnvPodBody.Children[1], obj);
								//}

								try
								{

									clsModuleInfo cmi = new clsModuleInfo();
									cmi.intModuleId = this.ModID;
									cmi.strModuleName = this.Text;
									cmi.strUri = this.WCFUri;
									cmi.strPageid = this.PageId;
									cmi.strTabid = this.TabId;
									cmi.ModPermissions = this.ModPer;
									cmi.strPodid = this.PID.ToString();
									cmi.strDropType = "Pod Type";


									for (int i = 0; i < lstUsersDropped.Count; i++)
									{
										if (lstUsersDropped[i] == ((VMukti.Presentation.Controls.CtlExpanderItem)e.Data.GetData(typeof(VMukti.Presentation.Controls.CtlExpanderItem))).Caption)
										{
											flag = true;
											break;
										}
									}


									if (!flag)
									{
										ComboItem cbiPodBuddy = new ComboItem();
										cbiPodBuddy.setName(((VMukti.Presentation.Controls.CtlExpanderItem)e.Data.GetData(typeof(VMukti.Presentation.Controls.CtlExpanderItem))).Caption);
										cmbPodBuddy.Items.Add(cbiPodBuddy);
										lstUsersDropped.Add(((VMukti.Presentation.Controls.CtlExpanderItem)e.Data.GetData(typeof(VMukti.Presentation.Controls.CtlExpanderItem))).Caption);
										cmi.lstUsersDropped = lstUsersDropped;
										if (EntCnvPodBodyDrop != null)
										{
											EntCnvPodBodyDrop(VMuktiInfo.CurrentPeer.DisplayName, ((VMukti.Presentation.Controls.CtlExpanderItem)e.Data.GetData(typeof(VMukti.Presentation.Controls.CtlExpanderItem))).Caption, "OPEN_MODULE", cmi);
										}
									}


								}
								catch (Exception exp)
								{
									//MessageBox.Show("cnvNew_Drop2" + exp.Message);
									exp.Data.Add("My Key", "cnvNew_Drop7--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
									ClsException.LogError(exp);
									ClsException.WriteToErrorLogFile(exp);
								}
							}
						}
						else
						{
							MessageBox.Show("Save the page to Collaborate");
						}
					}
				}
				#endregion
			}
			catch (Exception exp)
			{
				//MessageBox.Show("Canvas_Drop " + exp.Message);
				exp.Data.Add("My Key", "cnvNew_Drop8--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
				ClsException.LogError(exp);
				ClsException.WriteToErrorLogFile(exp);
			}
		}

		#endregion

		#region OtherMethods

		public void ControlDispatcher(object objnew)
		{
			try
			{
				this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, pDel, objnew);
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "ControlDispatcher()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		public void ControlThread(object objnew)
		{
			try
			{
				object[] obj = (object[])objnew;

				#region Collaborative
				if (obj.Length == 4)
				{
					int moduleid = (int)obj[0];
					string modulename = (string)obj[1];
					ClsPod podObj = new ClsPod();
					podObj = ClsPod.GetModInfo(moduleid);

					#region Downloading ZipFile

					string filename = podObj.ZipFile;

                    Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
					if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
					{
						Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
					}
					string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
					if (!File.Exists(destination + "\\" + filename))
					{
						WebClient wc = new WebClient();
						wc.DownloadFile(u, destination + "\\" + filename);
					}

					#endregion

					#region Extracting

					string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
					VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
					if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
					{
						fz.ExtractZip(destination + "\\" + filename, strModPath, null);
					}

					#endregion

					#region Loading ReferencedAssemblies

					//DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath);
					DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + filename.Split('.')[0]);
					ShowDirectory(dirinfomodule);

					for (int j = 0; j < al.Count; j++)
					{
						string[] arraysplit = al[j].ToString().Split('\\');
						if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
						{
							a = Assembly.LoadFrom(al[j].ToString());
							AssemblyName[] an = a.GetReferencedAssemblies();

							for (int alcount = 0; alcount < al.Count; alcount++)
							{
								string strsplit = al[alcount].ToString();
								string[] strold = strsplit.Split('\\');
								string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

								for (int asscount = 0; asscount < an.Length; asscount++)
								{
									if (an[asscount].Name == strnew)
									{
										Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
										AssemblyName[] anbal = assbal.GetReferencedAssemblies();
										for (int andal = 0; andal < al.Count; andal++)
										{
											string strsplitdal = al[andal].ToString();
											string[] strolddal = strsplitdal.Split('\\');
											string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

											for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
											{
												if (anbal[asscountdal].Name == strnewdal)
												{
													Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
												}
											}
										}
									}
								}
							}
							Type[] t1 = a.GetTypes();

							#region CreatingObject

							for (int k = 0; k < t1.Length; k++)
							{
								if (t1[k].Name == podObj.ClassName)
								{
									try
									{
										ConstructorInfo[] ci = t1[k].GetConstructors();

										for (int constcount = 0; constcount < ci.Length; constcount++)
										{
											ParameterInfo[] pi = ci[constcount].GetParameters();
											if (pi.Length == 4)
											{
												if (pi[0].ParameterType.Name == "PeerType")
												{
													object[] objArg = new object[4];
													//objArg[0] = VMuktiGlobal.objBindingType;
													//VMuktiInfo.CurrentPeer.CurrPeerType = VMuktiAPI.PeerType.NodeWithNetP2P;
													objArg[0] = VMuktiInfo.CurrentPeer.CurrPeerType;
													objArg[1] = obj[2].ToString();
													objArg[2] = obj[3];
													objArg[3] = "Host";


													object obj1 = Activator.CreateInstance(t1[k], BindingFlags.CreateInstance, null, objArg, new System.Globalization.CultureInfo("en-US"));
													//((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
													//((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

													cnvPodBody.Tag = t1[k].ToString();


													if (((UserControl)obj1).MinHeight.ToString() != "0")
													{
														this.Height = ((UserControl)obj1).MinHeight + 20.0;
														this.Width = ((UserControl)obj1).MinWidth + 13.0;

														((Resizer)(this.Parent)).Height = this.Height + 5.0;

														((Resizer)(this.Parent)).Width = this.Width + 5.0;
													}
													else
													{
														if (cnvPodBody.Height - 3.0 >= 0)
														{
															((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
														}
														else
														{
															((UserControl)obj1).Height = 0.0;
														}
														if (cnvPodBody.Width - 3.0 >= 0)
														{
															((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
														}
														else
														{
															((UserControl)obj1).Width = 0.0;
														}

													}

													//if (cnvPodBody.Height - 3.0 >= 0)
													//{
													//    ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
													//}
													//else
													//{
													//    ((UserControl)obj1).Height = 0.0;
													//}
													//if (cnvPodBody.Width - 3.0 >= 0)
													//{
													//    ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
													//}
													//else
													//{
													//    ((UserControl)obj1).Width = 0.0;
													//}
													//((UserControl)obj1).Drop += new DragEventHandler(CtlPod_Drop);                                                 
													//setdisplayname();
													cnvPodBody.Children.Add((UIElement)obj1);
													break;
												}
											}
											else
											{
												object obj1 = Activator.CreateInstance(t1[k]);
												//object obj1 = Activator.CreateInstance(t1[k], BindingFlags.CreateInstance, new Binder(), objArg, new System.Globalization.CultureInfo("en-US"));
												((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
												((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

												cnvPodBody.Tag = t1[k].ToString();
												if (((UserControl)obj1).MinHeight.ToString() != "0")
												{
													this.Height = ((UserControl)obj1).MinHeight + 20.0;
													this.Width = ((UserControl)obj1).MinWidth + 13.0;

													((Resizer)(this.Parent)).Height = this.Height + 5.0;

													((Resizer)(this.Parent)).Width = this.Width + 5.0;
												}
												else
												{
													if (cnvPodBody.Height - 3.0 >= 0)
													{
														((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
													}
													else
													{
														((UserControl)obj1).Height = 0.0;
													}
													if (cnvPodBody.Width - 3.0 >= 0)
													{
														((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
													}
													else
													{
														((UserControl)obj1).Width = 0.0;
													}

												}
												//if (cnvPodBody.Height - 3.0 >= 0)
												//{
												//    ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
												//}
												//else
												//{
												//    ((UserControl)obj1).Height = 0.0;
												//}
												//if (cnvPodBody.Width - 3.0 >= 0)
												//{
												//    ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
												//}
												//else
												//{
												//    ((UserControl)obj1).Width = 0.0;
												//}



												cnvPodBody.Children.Add((UIElement)obj1);
												break;
											}
										}
									}
									catch (Exception exp)
									{
										//MessageBox.Show("CreatingObject " + exp.Message);
										exp.Data.Add("My Key", "CreatingObject-1--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
										ClsException.LogError(exp);
										ClsException.WriteToErrorLogFile(exp);
									}
									lbPodBody.Visibility = Visibility.Hidden;
									this.PodVisible(true);
								}
							}
							#endregion
						}
					}
					#endregion
				}
				#endregion

				#region NonCollaborative
				else
				{
					int moduleid = (int)obj[0];
					string modulename = (string)obj[1];

					ClsPod podObj = new ClsPod();
					podObj = ClsPod.GetModInfo(moduleid);

					#region Downloading ZipFile

					string filename = podObj.ZipFile;

					//Uri u = new Uri("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/" + filename);
                    Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
					if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
					{
						Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
					}
					string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
					if (!File.Exists(destination + "\\" + filename))
					{
						WebClient wc = new WebClient();
						wc.DownloadFile(u, destination + "\\" + filename);
					}

					#endregion

					#region Extracting

					string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
					VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
					if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
					{
						fz.ExtractZip(destination + "\\" + filename, strModPath, null);
					}

					#endregion

					#region Loading ReferencedAssemblies

					//DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath);
					DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + filename.Split('.')[0]);
					ShowDirectory(dirinfomodule);

					for (int j = 0; j < al.Count; j++)
					{
						string[] arraysplit = al[j].ToString().Split('\\');
						if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
						{
							a = Assembly.LoadFrom(al[j].ToString());
							AssemblyName[] an = a.GetReferencedAssemblies();

							for (int alcount = 0; alcount < al.Count; alcount++)
							{
								string strsplit = al[alcount].ToString();
								string[] strold = strsplit.Split('\\');
								string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

								for (int asscount = 0; asscount < an.Length; asscount++)
								{
									if (an[asscount].Name == strnew)
									{
										Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
										AssemblyName[] anbal = assbal.GetReferencedAssemblies();
										for (int andal = 0; andal < al.Count; andal++)
										{
											string strsplitdal = al[andal].ToString();
											string[] strolddal = strsplitdal.Split('\\');
											string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

											for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
											{
												if (anbal[asscountdal].Name == strnewdal)
												{
													Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
												}
											}
										}
									}
								}
							}
							Type[] t1 = a.GetTypes();

							#region CreatingObject

							for (int k = 0; k < t1.Length; k++)
							{
								if (t1[k].Name == podObj.ClassName)
								{
									try
									{
										object[] objArg = new object[1];
										objArg[0] = obj[2];

										object obj1 = Activator.CreateInstance(t1[k], objArg);
										//object obj1 = Activator.CreateInstance(t1[k], BindingFlags.Public,null,objArg, new System.Globalization.CultureInfo("en-US"));
										((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
										((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

										cnvPodBody.Tag = t1[k].ToString();
										if (((UserControl)obj1).MinHeight.ToString() != "0")
										{
											this.Height = ((UserControl)obj1).MinHeight + 20.0;
											this.Width = ((UserControl)obj1).MinWidth + 13.0;

											((Resizer)(this.Parent)).Height = this.Height + 5.0;

											((Resizer)(this.Parent)).Width = this.Width + 5.0;
										}
										else
										{
											if (cnvPodBody.Height - 3.0 >= 0)
											{
												((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
											}
											else
											{
												((UserControl)obj1).Height = 0.0;
											}
											if (cnvPodBody.Width - 3.0 >= 0)
											{
												((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
											}
											else
											{
												((UserControl)obj1).Width = 0.0;
											}

										}

										cnvPodBody.Children.Add((UIElement)obj1);

									}
									catch (Exception exp)
									{
										//MessageBox.Show("CreatingObject " + exp.Message);
										exp.Data.Add("My Key", "CreatingObject-2--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
										ClsException.LogError(exp);
										ClsException.WriteToErrorLogFile(exp);
										cnvPodBody.Children.Add(new UIElement());
									}
									lbPodBody.Visibility = Visibility.Hidden;
									this.PodVisible(true);
									//this.Visibility = Visibility.Visible;
								}
							}
							#endregion
						}
					}
					#endregion

				}
				#endregion

				al.Clear();
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "ControlThread()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		private void setdisplayname()
		{
			//Pratik is not getting.
			//VMukti.Common.VMuktiGlobal.CallEventMethod(lname);
			//Pratik is not getting.
		}

		public void PodVisible(bool flag)
		{
			try
			{
				if (flag)
				{
					this.Visibility = Visibility.Visible;
				}
				else
				{
					this.Visibility = Visibility.Collapsed;
				}

				Type[] t3 = cnvPodBody.Children[1].GetType().GetInterfaces();

				if (flag)
				{

					for (int i = 0; i < t3.Length; i++)
					{
						if (t3[i].Name == "IsvcPodVisibleChange")
						{
							try
							{
								object[] obj = new object[] { true };
								System.Reflection.MethodInfo mi = t3[i].GetMethod("PodVisibility");
								mi.Invoke(cnvPodBody.Children[1], obj);
								break;
							}
							catch (Exception ex)
							{
								ex.Data.Add("My Key", "PodVisible()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
								ClsException.LogError(ex);
								ClsException.WriteToErrorLogFile(ex);

							}
						}
					}
				}
				else
				{

					for (int i = 0; i < t3.Length; i++)
					{
						if (t3[i].Name == "IsvcPodVisibleChange")
						{
							try
							{
								object[] obj = new object[] { false };
								System.Reflection.MethodInfo mi = t3[i].GetMethod("PodVisibility");
								mi.Invoke(cnvPodBody.Children[1], obj);
								break;
							}
							catch (Exception ex)
							{
								ex.Data.Add("My Key", "PodVisible()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
								ClsException.LogError(ex);
								ClsException.WriteToErrorLogFile(ex);

							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "PodVisible()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
			//}
		}

		public void ShowDirectory(DirectoryInfo dir)
		{
			try
			{
				foreach (FileInfo file in dir.GetFiles("*.dll"))
				{
					int hj = al.Add(file.FullName);
				}
				foreach (DirectoryInfo subDir in dir.GetDirectories())
				{
					ShowDirectory(subDir);
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "ShowDirectory()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		public void MySizeChanged(double height, double width, double left, double top, int pid, string tabid, string userid)
		{
			try
			{
				//if (MyRole == "Host" && this.PID != 0)
				//{                
				this.ResizePod = true;
				blnPodResize = true;
				this.Height = height;
				this.Width = width;
				this.SetValue(Canvas.LeftProperty, left);
				this.SetValue(Canvas.TopProperty, top);
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "MySizeChanged()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
			////CtlDesignerControl.channelPod.WSvcResetPod(left, top, width, height, pid, tabid, userid);
			//}
		}

		public void DynModuleDispatcher(object objnew)
		{
			try
			{
				this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, dModDel, objnew);
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "DynModuleDispatcher()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		public void ModuleThread(object objnew)
		{
			try
			{
				object[] obj = (object[])objnew;

				#region Collaborative
				if (obj.Length == 5)
				{
					int moduleid = (int)obj[0];
					string modulename = (string)obj[1];
					ClsPod podObj = new ClsPod();
					podObj = ClsPod.GetModInfo(moduleid);

					#region Downloading ZipFile

					string filename = podObj.ZipFile;

					//Uri u = new Uri("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/" + filename);
                    Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
					if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
					{
						Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
					}
					string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
					if (!File.Exists(destination + "\\" + filename))
					{
						WebClient wc = new WebClient();
						wc.DownloadFile(u, destination + "\\" + filename);
					}

					#endregion

					#region Extracting

					string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
					VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
					if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
					{
						fz.ExtractZip(destination + "\\" + filename, strModPath, null);
					}

					#endregion

					#region Loading ReferencedAssemblies

					//DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath);
					DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + filename.Split('.')[0]);
					ShowDirectory(dirinfomodule);

					for (int j = 0; j < al.Count; j++)
					{
						string[] arraysplit = al[j].ToString().Split('\\');
						if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
						{
							a = Assembly.LoadFrom(al[j].ToString());
							AssemblyName[] an = a.GetReferencedAssemblies();

							for (int alcount = 0; alcount < al.Count; alcount++)
							{
								string strsplit = al[alcount].ToString();
								string[] strold = strsplit.Split('\\');
								string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

								for (int asscount = 0; asscount < an.Length; asscount++)
								{
									if (an[asscount].Name == strnew)
									{
										Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
										AssemblyName[] anbal = assbal.GetReferencedAssemblies();
										for (int andal = 0; andal < al.Count; andal++)
										{
											string strsplitdal = al[andal].ToString();
											string[] strolddal = strsplitdal.Split('\\');
											string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

											for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
											{
												if (anbal[asscountdal].Name == strnewdal)
												{
													Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
												}
											}
										}
									}
								}
							}
							Type[] t1 = a.GetTypes();

							#region CreatingObject

							for (int k = 0; k < t1.Length; k++)
							{
								if (t1[k].Name == podObj.ClassName)
								{
									try
									{
										ConstructorInfo[] ci = t1[k].GetConstructors();

										for (int constcount = 0; constcount < ci.Length; constcount++)
										{
											ParameterInfo[] pi = ci[constcount].GetParameters();
											if (pi.Length == 4)
											{
												if (pi[0].ParameterType.Name == "PeerType")
												{
													object[] objArg = new object[4];
													//objArg[0] = VMuktiGlobal.objBindingType;
													//VMuktiInfo.CurrentPeer.CurrPeerType = VMuktiAPI.PeerType.NodeWithNetP2P;
													objArg[0] = VMuktiInfo.CurrentPeer.CurrPeerType;
													objArg[1] = obj[2].ToString();
													objArg[2] = obj[3];
													objArg[3] = "Guest";

													object obj1 = Activator.CreateInstance(t1[k], BindingFlags.CreateInstance, null, objArg, new System.Globalization.CultureInfo("en-US"));
													//((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
													//((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

													cnvPodBody.Tag = t1[k].ToString();


													//if (((UserControl)obj1).MinHeight.ToString() != "0")
													//{
													//    this.Height = ((UserControl)obj1).MinHeight + 20.0;
													//    this.Width = ((UserControl)obj1).MinWidth + 13.0;

													//    ((Resizer)(this.Parent)).Height = this.Height + 5.0;

													//    ((Resizer)(this.Parent)).Width = this.Width + 5.0;
													//}
													//else
													//{
													//    if (cnvPodBody.Height - 3.0 >= 0)
													//    {
													//        ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
													//    }
													//    else
													//    {
													//        ((UserControl)obj1).Height = 0.0;
													//    }
													//    if (cnvPodBody.Width - 3.0 >= 0)
													//    {
													//        ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
													//    }
													//    else
													//    {
													//        ((UserControl)obj1).Width = 0.0;
													//    }

													//}

													//if (cnvPodBody.Height - 3.0 >= 0)
													//{
													//    ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
													//}
													//else
													//{
													//    ((UserControl)obj1).Height = 0.0;
													//}
													//if (cnvPodBody.Width - 3.0 >= 0)
													//{
													//    ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
													//}
													//else
													//{
													//    ((UserControl)obj1).Width = 0.0;
													//}
													//((UserControl)obj1).Drop += new DragEventHandler(CtlPod_Drop);                                                 
													//setdisplayname();
													cnvPodBody.Children.Add((UIElement)obj1);
													//MethodInfo mi = cnvPodBody.Children[1].GetType().GetMethod("BuddySelected");
													//if (mi != null)
													//{
													//    List<string> lstTag = new List<string>();
													//    lstTag.Add(obj[4].ToString());
													//    object[] obj2 = new object[] { lstTag };
													//    mi.Invoke(cnvPodBody.Children[1], obj2);
													//}
													break;
												}
											}
											else
											{
												object obj1 = Activator.CreateInstance(t1[k]);
												//object obj1 = Activator.CreateInstance(t1[k], BindingFlags.CreateInstance, new Binder(), objArg, new System.Globalization.CultureInfo("en-US"));
												((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
												((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

												cnvPodBody.Tag = t1[k].ToString();
												//if (((UserControl)obj1).MinHeight.ToString() != "0")
												//{
												//    this.Height = ((UserControl)obj1).MinHeight + 20.0;
												//    this.Width = ((UserControl)obj1).MinWidth + 13.0;

												//    ((Resizer)(this.Parent)).Height = this.Height + 5.0;

												//    ((Resizer)(this.Parent)).Width = this.Width + 5.0;
												//}
												//else
												//{
												//    if (cnvPodBody.Height - 3.0 >= 0)
												//    {
												//        ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
												//    }
												//    else
												//    {
												//        ((UserControl)obj1).Height = 0.0;
												//    }
												//    if (cnvPodBody.Width - 3.0 >= 0)
												//    {
												//        ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
												//    }
												//    else
												//    {
												//        ((UserControl)obj1).Width = 0.0;
												//    }

												//}
												//if (cnvPodBody.Height - 3.0 >= 0)
												//{
												//    ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
												//}
												//else
												//{
												//    ((UserControl)obj1).Height = 0.0;
												//}
												//if (cnvPodBody.Width - 3.0 >= 0)
												//{
												//    ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
												//}
												//else
												//{
												//    ((UserControl)obj1).Width = 0.0;
												//}



												cnvPodBody.Children.Add((UIElement)obj1);
												//MethodInfo mi = cnvPodBody.Children[cnvPodBody.Children.Count - 1].GetType().GetMethod("BuddySelected");
												//if (mi != null)
												//{
												//    List<string> lstTag = new List<string>();
												//    lstTag.Add(obj[4].ToString());
												//    object[] obj2 = new object[] { lstTag };
												//    mi.Invoke(cnvPodBody.Children[cnvPodBody.Children.Count - 1], obj2);
												//}
												break;
											}
										}
									}
									catch (Exception exp)
									{
										//MessageBox.Show("CreatingObject " + exp.Message);
										exp.Data.Add("My Key", "CreatingObject-3--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
										ClsException.LogError(exp);
										ClsException.WriteToErrorLogFile(exp);
									}
									lbPodBody.Visibility = Visibility.Hidden;
									this.PodVisible(true);
								}
							}
							#endregion
						}
					}
					#endregion
				}
				#endregion

				#region NonCollaborative
				else
				{
					int moduleid = (int)obj[0];
					string modulename = (string)obj[1];

					ClsPod podObj = new ClsPod();
					podObj = ClsPod.GetModInfo(moduleid);

					#region Downloading ZipFile

					string filename = podObj.ZipFile;

					//Uri u = new Uri("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/" + filename);
                    Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
					if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
					{
						Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
					}
					string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
					if (!File.Exists(destination + "\\" + filename))
					{
						WebClient wc = new WebClient();
						wc.DownloadFile(u, destination + "\\" + filename);
					}

					#endregion

					#region Extracting

					string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
					VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
					if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
					{
						fz.ExtractZip(destination + "\\" + filename, strModPath, null);
					}

					#endregion

					#region Loading ReferencedAssemblies

					//DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath);
					DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + filename.Split('.')[0]);
					ShowDirectory(dirinfomodule);

					for (int j = 0; j < al.Count; j++)
					{
						string[] arraysplit = al[j].ToString().Split('\\');
						if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
						{
							a = Assembly.LoadFrom(al[j].ToString());
							AssemblyName[] an = a.GetReferencedAssemblies();

							for (int alcount = 0; alcount < al.Count; alcount++)
							{
								string strsplit = al[alcount].ToString();
								string[] strold = strsplit.Split('\\');
								string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

								for (int asscount = 0; asscount < an.Length; asscount++)
								{
									if (an[asscount].Name == strnew)
									{
										Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
										AssemblyName[] anbal = assbal.GetReferencedAssemblies();
										for (int andal = 0; andal < al.Count; andal++)
										{
											string strsplitdal = al[andal].ToString();
											string[] strolddal = strsplitdal.Split('\\');
											string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

											for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
											{
												if (anbal[asscountdal].Name == strnewdal)
												{
													Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
												}
											}
										}
									}
								}
							}
							Type[] t1 = a.GetTypes();

							#region CreatingObject

							for (int k = 0; k < t1.Length; k++)
							{
								if (t1[k].Name == podObj.ClassName)
								{
									try
									{
										object[] objArg = new object[1];
										objArg[0] = obj[2];

										object obj1 = Activator.CreateInstance(t1[k], objArg);
										//object obj1 = Activator.CreateInstance(t1[k], BindingFlags.Public,null,objArg, new System.Globalization.CultureInfo("en-US"));
										((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
										((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

										cnvPodBody.Tag = t1[k].ToString();
										//if (((UserControl)obj1).MinHeight.ToString() != "0")
										//{
										//    this.Height = ((UserControl)obj1).MinHeight + 20.0;
										//    this.Width = ((UserControl)obj1).MinWidth + 13.0;

										//    ((Resizer)(this.Parent)).Height = this.Height + 5.0;

										//    ((Resizer)(this.Parent)).Width = this.Width + 5.0;
										//}
										//else
										//{
										//    if (cnvPodBody.Height - 3.0 >= 0)
										//    {
										//        ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
										//    }
										//    else
										//    {
										//        ((UserControl)obj1).Height = 0.0;
										//    }
										//    if (cnvPodBody.Width - 3.0 >= 0)
										//    {
										//        ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
										//    }
										//    else
										//    {
										//        ((UserControl)obj1).Width = 0.0;
										//    }

										//}



										cnvPodBody.Children.Add((UIElement)obj1);
										//MethodInfo mi = cnvPodBody.Children[cnvPodBody.Children.Count - 1].GetType().GetMethod("BuddySelected");
										//if (mi != null)
										//{
										//    List<string> lstTag = new List<string>();
										//    lstTag.Add(obj[4].ToString());
										//    object[] obj2 = new object[] { lstTag };
										//    mi.Invoke(cnvPodBody.Children[cnvPodBody.Children.Count - 1], obj2);
										//}
										break;
									}
									catch (Exception exp)
									{
										//MessageBox.Show("CreatingObject " + exp.Message);
										exp.Data.Add("My Key", "CreatingObject-4--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
										ClsException.LogError(exp);
										ClsException.WriteToErrorLogFile(exp);
										cnvPodBody.Children.Add(new UIElement());
									}
									lbPodBody.Visibility = Visibility.Hidden;
									this.PodVisible(true);
									//this.Visibility = Visibility.Visible;
								}
							}
							#endregion
						}
					}
					#endregion

				}
				#endregion

				al.Clear();
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "ModuleThread()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		public void PageDispatcher(object objnew)
		{
			try
			{
				this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, dPageDel, objnew);
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "PageDispatcher()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		public void PageThread(object objnew)
		{
			try
			{
				object[] obj = (object[])objnew;

				#region Collaborative
				if (obj.Length == 5)
				{
					int moduleid = (int)obj[0];
					string modulename = (string)obj[1];
					ClsPod podObj = new ClsPod();
					podObj = ClsPod.GetModInfo(moduleid);

					#region Downloading ZipFile

					string filename = podObj.ZipFile;

					//Uri u = new Uri("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/" + filename);
                    Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
					if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
					{
						Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
					}
					string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
					if (!File.Exists(destination + "\\" + filename))
					{
						WebClient wc = new WebClient();
						wc.DownloadFile(u, destination + "\\" + filename);
					}

					#endregion

					#region Extracting

					string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
					VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
					if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
					{
						fz.ExtractZip(destination + "\\" + filename, strModPath, null);
					}

					#endregion

					#region Loading ReferencedAssemblies

					//DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath);
					DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + filename.Split('.')[0]);
					ShowDirectory(dirinfomodule);

					for (int j = 0; j < al.Count; j++)
					{
						string[] arraysplit = al[j].ToString().Split('\\');
						if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
						{
							a = Assembly.LoadFrom(al[j].ToString());
							AssemblyName[] an = a.GetReferencedAssemblies();

							for (int alcount = 0; alcount < al.Count; alcount++)
							{
								string strsplit = al[alcount].ToString();
								string[] strold = strsplit.Split('\\');
								string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

								for (int asscount = 0; asscount < an.Length; asscount++)
								{
									if (an[asscount].Name == strnew)
									{
										Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
										AssemblyName[] anbal = assbal.GetReferencedAssemblies();
										for (int andal = 0; andal < al.Count; andal++)
										{
											string strsplitdal = al[andal].ToString();
											string[] strolddal = strsplitdal.Split('\\');
											string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

											for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
											{
												if (anbal[asscountdal].Name == strnewdal)
												{
													Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
												}
											}
										}
									}
								}
							}
							Type[] t1 = a.GetTypes();

							#region CreatingObject

							for (int k = 0; k < t1.Length; k++)
							{
								if (t1[k].Name == podObj.ClassName)
								{
									try
									{
										ConstructorInfo[] ci = t1[k].GetConstructors();

										for (int constcount = 0; constcount < ci.Length; constcount++)
										{
											ParameterInfo[] pi = ci[constcount].GetParameters();
											if (pi.Length == 4)
											{
												if (pi[0].ParameterType.Name == "PeerType")
												{
													object[] objArg = new object[4];
													//objArg[0] = VMuktiGlobal.objBindingType;
													//VMuktiInfo.CurrentPeer.CurrPeerType = VMuktiAPI.PeerType.NodeWithNetP2P;
													objArg[0] = VMuktiInfo.CurrentPeer.CurrPeerType;
													objArg[1] = obj[2].ToString();
													objArg[2] = obj[3];
													objArg[3] = "Host";


													object obj1 = Activator.CreateInstance(t1[k], BindingFlags.CreateInstance, null, objArg, new System.Globalization.CultureInfo("en-US"));
													//((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
													//((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

													cnvPodBody.Tag = t1[k].ToString();

													if (!(bool)obj[4])
													{
														if (((UserControl)obj1).MinHeight.ToString() != "0")
														{
															this.Height = ((UserControl)obj1).MinHeight + 20.0;
															this.Width = ((UserControl)obj1).MinWidth + 13.0;

															((Resizer)(this.Parent)).Height = this.Height + 5.0;

															((Resizer)(this.Parent)).Width = this.Width + 5.0;
														}
														else
														{
															if (cnvPodBody.Height - 3.0 >= 0)
															{
																((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
															}
															else
															{
																((UserControl)obj1).Height = 0.0;
															}
															if (cnvPodBody.Width - 3.0 >= 0)
															{
																((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
															}
															else
															{
																((UserControl)obj1).Width = 0.0;
															}

														}

													}

													//if (cnvPodBody.Height - 3.0 >= 0)
													//{
													//    ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
													//}
													//else
													//{
													//    ((UserControl)obj1).Height = 0.0;
													//}
													//if (cnvPodBody.Width - 3.0 >= 0)
													//{
													//    ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
													//}
													//else
													//{
													//    ((UserControl)obj1).Width = 0.0;
													//}
													//((UserControl)obj1).Drop += new DragEventHandler(CtlPod_Drop);                                                 
													//setdisplayname();
													cnvPodBody.Children.Add((UIElement)obj1);
													break;
												}
											}
											else
											{
												object obj1 = Activator.CreateInstance(t1[k]);
												//object obj1 = Activator.CreateInstance(t1[k], BindingFlags.CreateInstance, new Binder(), objArg, new System.Globalization.CultureInfo("en-US"));
												((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
												((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

												cnvPodBody.Tag = t1[k].ToString();
												if (((UserControl)obj1).MinHeight.ToString() != "0")
												{
													this.Height = ((UserControl)obj1).MinHeight + 20.0;
													this.Width = ((UserControl)obj1).MinWidth + 13.0;

													((Resizer)(this.Parent)).Height = this.Height + 5.0;

													((Resizer)(this.Parent)).Width = this.Width + 5.0;
												}
												else
												{
													if (cnvPodBody.Height - 3.0 >= 0)
													{
														((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
													}
													else
													{
														((UserControl)obj1).Height = 0.0;
													}
													if (cnvPodBody.Width - 3.0 >= 0)
													{
														((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
													}
													else
													{
														((UserControl)obj1).Width = 0.0;
													}

												}
												//if (cnvPodBody.Height - 3.0 >= 0)
												//{
												//    ((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
												//}
												//else
												//{
												//    ((UserControl)obj1).Height = 0.0;
												//}
												//if (cnvPodBody.Width - 3.0 >= 0)
												//{
												//    ((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
												//}
												//else
												//{
												//    ((UserControl)obj1).Width = 0.0;
												//}



												cnvPodBody.Children.Add((UIElement)obj1);
												break;
											}
										}
									}
									catch (Exception exp)
									{
										//MessageBox.Show("CreatingObject " + exp.Message);
										exp.Data.Add("My Key", "CreatingObject-5--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
										ClsException.LogError(exp);
										ClsException.WriteToErrorLogFile(exp);
									}
									lbPodBody.Visibility = Visibility.Hidden;
									this.PodVisible(true);
								}
							}
							#endregion
						}
					}
					#endregion
				}
				#endregion

				#region NonCollaborative
				else
				{
					int moduleid = (int)obj[0];
					string modulename = (string)obj[1];

					ClsPod podObj = new ClsPod();
					podObj = ClsPod.GetModInfo(moduleid);

					#region Downloading ZipFile

					string filename = podObj.ZipFile;

					//Uri u = new Uri("http://" + VMuktiAPI.VMuktiInfo.BootStrapIPs[0] + "/VMukti/" + filename);
                    Uri u = new Uri(VMuktiAPI.VMuktiInfo.ZipFileDownloadLink + filename);
					if (!Directory.Exists(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files")))
					{
						Directory.CreateDirectory(ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files"));
					}
					string destination = ass.Location.Replace("VMukti.Presentation.exe", @"Zip Files");
					if (!File.Exists(destination + "\\" + filename))
					{
						WebClient wc = new WebClient();
						wc.DownloadFile(u, destination + "\\" + filename);
					}

					#endregion

					#region Extracting

					string strModPath = ass.Location.Replace("VMukti.Presentation.exe", @"Modules");
					VMukti.ZipUnzip.Zip.FastZip fz = new VMukti.ZipUnzip.Zip.FastZip();
					if (!Directory.Exists(strModPath + "\\" + filename.Split('.')[0]))
					{
						fz.ExtractZip(destination + "\\" + filename, strModPath, null);
					}

					#endregion

					#region Loading ReferencedAssemblies

					//DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath);
					DirectoryInfo dirinfomodule = new DirectoryInfo(strModPath + "\\" + filename.Split('.')[0]);
					ShowDirectory(dirinfomodule);

					for (int j = 0; j < al.Count; j++)
					{
						string[] arraysplit = al[j].ToString().Split('\\');
						if (arraysplit[arraysplit.Length - 1].ToString() == podObj.AssemblyFile)
						{
							a = Assembly.LoadFrom(al[j].ToString());
							AssemblyName[] an = a.GetReferencedAssemblies();

							for (int alcount = 0; alcount < al.Count; alcount++)
							{
								string strsplit = al[alcount].ToString();
								string[] strold = strsplit.Split('\\');
								string strnew = strold[strold.Length - 1].Substring(0, strold[strold.Length - 1].Length - 4);

								for (int asscount = 0; asscount < an.Length; asscount++)
								{
									if (an[asscount].Name == strnew)
									{
										Assembly assbal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[alcount].ToString()).GetName());
										AssemblyName[] anbal = assbal.GetReferencedAssemblies();
										for (int andal = 0; andal < al.Count; andal++)
										{
											string strsplitdal = al[andal].ToString();
											string[] strolddal = strsplitdal.Split('\\');
											string strnewdal = strolddal[strolddal.Length - 1].Substring(0, strolddal[strolddal.Length - 1].Length - 4);

											for (int asscountdal = 0; asscountdal < anbal.Length; asscountdal++)
											{
												if (anbal[asscountdal].Name == strnewdal)
												{
													Assembly assdal = System.AppDomain.CurrentDomain.Load(System.Reflection.Assembly.LoadFrom(al[andal].ToString()).GetName());
												}
											}
										}
									}
								}
							}
							Type[] t1 = a.GetTypes();

							#region CreatingObject

							for (int k = 0; k < t1.Length; k++)
							{
								if (t1[k].Name == podObj.ClassName)
								{
									try
									{
										object[] objArg = new object[1];
										objArg[0] = obj[2];

										object obj1 = Activator.CreateInstance(t1[k], objArg);
										//object obj1 = Activator.CreateInstance(t1[k], BindingFlags.Public,null,objArg, new System.Globalization.CultureInfo("en-US"));
										((UserControl)obj1).SetValue(Canvas.LeftProperty, 0.0);
										((UserControl)obj1).SetValue(Canvas.TopProperty, 0.0);

										cnvPodBody.Tag = t1[k].ToString();

										if (!(bool)obj[3])
										{
											if (((UserControl)obj1).MinHeight.ToString() != "0")
											{
												this.Height = ((UserControl)obj1).MinHeight + 20.0;
												this.Width = ((UserControl)obj1).MinWidth + 13.0;

												this.DBHeight = this.Height;
												this.DBWidth = this.Width;

												((Resizer)(this.Parent)).Height = this.Height + 5.0;

												((Resizer)(this.Parent)).Width = this.Width + 5.0;

												//double top = double.Parse(this.GetValue(Canvas.TopProperty).ToString());
												//MessageBox.Show(this.GetValue(Canvas.LeftProperty).ToString());
												//this.SetValue(Canvas.TopProperty,


											}
											else
											{
												if (cnvPodBody.Height - 3.0 >= 0)
												{
													((UserControl)obj1).Height = cnvPodBody.Height - 3.0;
												}
												else
												{
													((UserControl)obj1).Height = 0.0;
												}
												if (cnvPodBody.Width - 3.0 >= 0)
												{
													((UserControl)obj1).Width = (cnvPodBody.Width - 3.0);
												}
												else
												{
													((UserControl)obj1).Width = 0.0;
												}




											}
										}
										cnvPodBody.Children.Add((UIElement)obj1);

									}
									catch (Exception exp)
									{
										//MessageBox.Show("CreatingObject " + exp.Message);
										exp.Data.Add("My Key", "CreatingObject-7--:--CtlPageTab.cs--:--" + exp.Message + " :--:--");
										ClsException.LogError(exp);
										ClsException.WriteToErrorLogFile(exp);
										cnvPodBody.Children.Add(new UIElement());
									}
									lbPodBody.Visibility = Visibility.Hidden;
									this.PodVisible(true);
									//this.Visibility = Visibility.Visible;
								}
							}
							#endregion
						}
					}
					#endregion

				}
				#endregion

				al.Clear();
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "PageThread()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}


		#endregion

		#region DisposeMethods

		public void Dispose()
		{
			try
			{
				Dispose(true);
				GC.SuppressFinalize(this);
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "Dispose()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		private void Dispose(bool disposing)
		{
			try
			{
				if (!this.blndisposed)
				{
					if (disposing)
					{
						if (al != null)
						{
							al = null;
						}


						if (pDel != null)
						{
							pDel = null;
						}

						if (dModDel != null)
						{
							dModDel = null;
						}

						if (dPageDel != null)
						{
							dPageDel = null;
						}
						if (ass != null)
						{
							ass = null;
						}
						if (a != null)
						{
							a = null;
						}

						if (EntMainPodMouseDown != null)
						{
							EntMainPodMouseDown = null;
						}

						if (EntCnvPodBodyDrop != null)
						{
							EntCnvPodBodyDrop = null;
						}

						if (EntSavePage != null)
						{
							EntSavePage = null;
						}

						if (lstUsersDropped != null)
						{
							lstUsersDropped = null;
						}
					}
					blndisposed = true;

				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "Dispose()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		~CtlPod()
		{
			try
			{
				Dispose(false);
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "CtlPod()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		#endregion

		string lname;

		public void displayname(string from)
		{
			try
			{
				List<string> lstTag = new List<string>();
				lstTag.Add(from);
				MethodInfo mi = cnvPodBody.Children[1].GetType().GetMethod("BuddySelected");
				if (mi != null)
				{
					object[] obj = new object[] { lstTag };
					mi.Invoke(cnvPodBody.Children[1], obj);
				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "displayname()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		private void btnHidePanel_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				if (rowDef1.Height.Value == 25.0)
				{
					//this.BeginStoryboard((Storyboard)this.Resources["OnCloseClick"], HandoffBehavior.Compose, false);
					rowDef1.Height = new GridLength(0);
					//cnvPodBody.Background = (Brush)App.Current.Resources["PodBackground"];
				}
				else
				{
					//this.BeginStoryboard((Storyboard)this.Resources["OnOpenClick"], HandoffBehavior.Compose, true);
					rowDef1.Height = new GridLength(25.0, GridUnitType.Pixel);
					//cnvPodBody.Background = (Brush)App.Current.Resources["PodSQBG"];

				}
			}
			catch (Exception ex)
			{
				ex.Data.Add("My Key", "btnHidePanel_Click()--:--CtlPod.xaml.cs--:--" + ex.Message + " :--:--");
				ClsException.LogError(ex);
				ClsException.WriteToErrorLogFile(ex);

			}
		}

		private void cmbPodBuddy_MouseLeave(object sender, MouseEventArgs e)
		{
			if (cmbPodBuddy.IsDropDownOpen)
			{
				cmbPodBuddy.IsDropDownOpen = false;
			}
		}

		private void cmbPodBuddy_MouseEnter(object sender, MouseEventArgs e)
		{
			if (cmbPodBuddy.Items.Count > 0)
			{
				cmbPodBuddy.IsDropDownOpen = true;
			}
		}
	}
}
